import React from "react";
import {connect} from "react-redux"
import {changeNewsList} from "../store/actions/news"
import {getNewList} from "../api/new";
class News extends React.Component{
    componentDidMount() {
        getNewList(1,10).then(res=>{
            console.log(res.data.rows)
            this.props.dispatchChangeNewsList(res.data.rows)
        })
    }

    render() {
        const {newsList} = this.props
        return (
            <div>
                {
                    newsList.map(item=>(
                        <div key={item.articleId}>{item.title}</div>
                    ))
                }
            </div>
        )
    }
}
export default connect(state=>({
   newsList: state.newsList
}),dispatch=>({
    dispatchChangeNewsList(list){
        dispatch(changeNewsList(list))
    }
}))(News)